import type * as T from './type'
import http from '@/utils/http'
import type { LabelValueState } from '@/types/global'

export type * from './type'

/**
 * 字典列表
 * @param query
 */
export function listDict(query?: T.DictQuery) {
  return http.post<T.DictResp[]>(`/system/dict/list`, query)
}

/**
 * 字典详情
 * @param id 字典ID
 */
export function getDict(id: string) {
  return http.get<T.DictResp>(`/system/dict/detail/${id}`)
}

/**
 * 字典新增
 * @param data
 */
export function addDict(data: any) {
  return http.post(`/system/dict/create`, data)
}

/**
 * 字典修改
 * @param id
 * @param data
 */
export function updateDict(id: string, data: any) {
  return http.put(`/system/dict/update/${id}`, data)
}

/**
 * 字典删除
 * @param id 字典ID
 */
export function deleteDict(id: string) {
  return http.del(`/system/dict/delete/${id}`)
}

/**
 * 字典缓存清除
 * @param code
 */
export function clearDictCache(code: string) {
  return http.del(`/system/dict/cache/clear/${code}`)
}

/**
 * 字典项分页
 * @param query
 */
export function pageDictItem(query: T.DictItemPageQuery) {
  return http.post<PageRes<T.DictItemResp[]>>(`/system/dict/item/page`, query)
}

/**
 * 字典项详情
 * @param id
 */
export function getDictItem(id: string) {
  return http.get<T.DictItemResp>(`/system/dict/item/detail/${id}`)
}

/**
 * 依据编码查询字典项
 * @param code
 */
export function listDictItemByCode(code: string) {
  return http.get<LabelValueState[]>(`/system/dict/item/list/${code}`)
}

/**
 * 字典项新增
 * @param data
 */
export function addDictItem(data: any) {
  return http.post(`/system/dict/item/create`, data)
}

/**
 * 字典项修改
 * @param data
 * @param id
 */
export function updateDictItem(data: any, id: string) {
  return http.put(`/system/dict/item/update/${id}`, data)
}

/**
 * 字典项删除
 * @param id
 */
export function deleteDictItem(id: string) {
  return http.del(`/system/dict/item/delete/${id}`)
}
